package me.fung.wubi.app.component.swing

import javax.swing.JComboBox

@Suppress("UNCHECKED_CAST")
fun <T> comboBoxBuilder(list: List<T>, onSelect: (T) -> Unit): JComboBox<T> {
    val comboBox = JComboBox<T>().apply {
        list.forEach { addItem(it) }
        this.addActionListener {
            val item = this.selectedItem
            if (item != null) {
                onSelect(item as T)
            }
        }
    }
    return comboBox
}